package com.huiquan.vocab.dao;

import com.huiquan.framework.base.EnhancedBaseDao;
import com.huiquan.vocab.domain.VocabElementChange;
import com.ibatis.sqlmap.client.SqlMapClient;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class VocabElementChangeDao extends EnhancedBaseDao<VocabElementChange> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "VOCAB_ELEMENT_CHANGE.";

	public VocabElementChangeDao() {
		super(space);
	}

	public void deleteSplitByEid(Long eid) {
		this.delete(space + "DELETE_SPLIT_BY_EID", eid, sqlMapClient);
	}

	public void insertBatch( List<VocabElementChange> synonymList) {
		int start = 0, end, size = synonymList.size();
		List<VocabElementChange> tempList;
//        List<Map<String,String>> values = new ArrayList<>();
//        for(VocabElementChange value:synonymList){
//            Map<String,String> change = new HashMap<>();
//            change.put("eid",value.getEid()+"");
//            change.put("rid",value.getRid()+"");
//            change.put("type",value.getType()+"");
//            values.add(change);
//        }
		while (start < size) {
			if (start + 2000 < size) {
				end = start + 2000;
			} else {
				end = size;
			}
			tempList = synonymList.subList(start, end);
			this.insert(space + "BATCH_INSERT", tempList, sqlMapClient);
			start += 2000;
		}
	}
}
